<template>
  <uni-nav-bar title="补液员列表" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="package">{{TeamInfo.station.name}}</view>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <FriendList :frinedList="frinedList" :show="true" @del="del"></FriendList>
  </scroll-view>
  <view class="add" @click="navTo('administrator/rehydrator/addDriver')">新增</view>
</template>

<script setup lang="ts">
  import { navBack, navTo } from '@/utils/navigator';
  import FriendList from '@c/administrator/List/friendList.vue';
  import { ref } from 'vue';
  import { onShow } from '@dcloudio/uni-app';
  import { toPublish } from '@mqtt';
  import { getDeliveryDriverList } from '@/gql/administrator';
  import { showLoading, errorToast, successToast } from '@/utils/prompt';
  import { information } from '@/stores/administrator';
  const TeamInfo = information();
  const pageHeight = ref();
  const frinedList = ref([])
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 180;
    },
  });
  onShow(() => {
    init()
  })
  function init() {
    showLoading()
    const payload = {
      query: getDeliveryDriverList,
      variables: {
        delivery_id: Number(TeamInfo.station.id)
      },
    };
    toPublish(
      'ql/control/getDeliveryDriverList',
      payload,
      (obj : any) => {
        uni.hideLoading();
        const { getDeliveryDriverList } = obj.data;
        frinedList.value = getDeliveryDriverList
      }
    );
  }
  //删除补液员
  function del(num : number,driverId:number) {
    showLoading('');
    const payload = {
      id: num,
    };
    toPublish('control/delDeliveryDriver', payload, (obj : any) => {
      uni.hideLoading();
      const { code, msg } = obj;
      if (code === 1) {
        successToast(msg)
        frinedList.value = frinedList.value.filter((item) => item.id == num ? item = null : item)
      } else {
        errorToast(msg)
      }
    });
  }
</script>

<style scoped lang="less">
  .add {
    width: 480rpx;
    height: 100rpx;
    background: linear-gradient(-10deg, #2C96F9, #1B91FF);
    border-radius: 5px;
    text-align: center;
    line-height: 100rpx;
    color: #fff;
    margin: 20rpx auto;
    font-size: 32rpx;
  }
</style>